package com.ch.forum.controller;

import com.ch.forum.bo.ResponseResult;
import com.ch.forum.model.BuySaleReward;
import com.ch.forum.model.MyBitCoinModel;
import com.ch.forum.service.BuySaleRewardService;
import com.ch.forum.service.IStockRestApi;
import com.ch.forum.service.MyBitCoinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/stock")
public class StockController {

    @Autowired
    private IStockRestApi iStockRestApi;

    @Autowired
    private MyBitCoinService myBitCoinService;

    @Autowired
    private BuySaleRewardService buySaleRewardService;

    @GetMapping("/market-list")
    public ResponseResult marketList(){
        try {
            return new ResponseResult(true, iStockRestApi.marketlist());
        } catch (Exception e) {
            return new ResponseResult(false, e.getMessage());
        }
    }

    @GetMapping("/ticker/{pair}")
    public ResponseResult tickerPair(@PathVariable String pair){
        try {
            return new ResponseResult(true, iStockRestApi.ticker(pair));
        } catch (Exception e) {
            return new ResponseResult(false, e.getMessage());
        }
    }

    @GetMapping("/my-bit-coin")
    public ResponseResult findMyBitCoin(){
        return myBitCoinService.findAll();
    }

    @PostMapping("/my-bit-coin")
    public ResponseResult addMyBitCoin(MyBitCoinModel model){
        return myBitCoinService.add(model);
    }

    @PostMapping("/my-bit-coin/update")
    public ResponseResult updateMyBitCoin(MyBitCoinModel model){
        return myBitCoinService.update(model);
    }

    @GetMapping("/my-bit-coin/{id}")
    public ResponseResult findOne(@PathVariable("id")Long id){
        return myBitCoinService.findOne(id);
    }

    @PostMapping("/recharge")
    public ResponseResult recharge(BuySaleReward param){
        return buySaleRewardService.recharge(param);
    }

    @PostMapping("/reflect")
    public ResponseResult reflect(BuySaleReward param){
        return buySaleRewardService.reflect(param);
    }

    @PostMapping("/buy")
    public ResponseResult buy(BuySaleReward param){
        return buySaleRewardService.buyIn(param);
    }

    @PostMapping("/sale")
    public ResponseResult sale(BuySaleReward param){
        return buySaleRewardService.saleOut(param);
    }

    /**
     *  充值未审核列表
     * @return
     */
    @GetMapping("/recharges")
    public ResponseResult rechargeList(){
        return buySaleRewardService.rechargeList();
    }

    @GetMapping("/reflects")
    public ResponseResult reflectList(){
        return buySaleRewardService.findReflectList();
    }

    @GetMapping("/update/{id}")
    public ResponseResult updateStatus(@PathVariable Long id){
        return buySaleRewardService.updateStatus(id);
    }

    @GetMapping("/user-reward/{id}")
    public ResponseResult findUserReard(@PathVariable("id")Long id){
        return buySaleRewardService.findUserReard(id);
    }

}
